﻿using System.Data;
using System.Data.Common;

namespace Songhay.Data.GenericWeb.Procedure
{
    internal static partial class Get
    {
        internal static string FragmentByName(DbConnection commonConnection, string fragmentName, string columnName)
        {
            using(DbCommand cmd = commonConnection.CreateCommand())
            {
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = @"
SELECT
    *
FROM
    Fragment
WHERE
    fragmentName = @fragmentName
";
                DbParameter param = cmd.CreateParameter();
                param.ParameterName = "@fragmentName";
                param.Value = fragmentName;
                cmd.Parameters.Add(param);
                using(DbDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                {
                    if(reader.Read())
                        return reader[columnName].ToString();
                    else
                        return null;
                }
            }
        }
    }
}
